package day04;

import java.util.Scanner;

/*
 从键盘输入年月,在控制台打印当月日历,已知1900.1.1日为星期一
 */
//问题:输入月份的1号为星期几
//解决:天数差%7+1为该月第一天星期.
public class printCalendar {
    public static void main(String[] args) {
        System.out.println("一\t二\t三\t四\t五\t六\t日");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入年份");
        int year = sc.nextInt();
        System.out.println("请输入月份");
        int month = sc.nextInt();
        int cunt1 = 0;
        int cunt2 = 0;
        for (int i = year - 1; i > 1900; i--) {
            cunt1 += yearDay(i);
            for (int j = month - 1; j > month; j--) {
                cunt2 += monthDay(i,j);
            }
        }
        int count=cunt1+cunt2;
        int day1=count%7;
        System.out.println(day1);

    }

    public static int yearDay(int year) {
        int days = 0;
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            return 366;
        }
        return 365;
    }


    public static int monthDay(int year, int month) {
        int days = 0;
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                days = 30;
                break;
            case 2:
                if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                    days = 29;
                } else {
                    days = 28;
                }
        }
        return days;
    }
}
